package pl.edu.agh.iosr.gamblingzone.adminpanel.action;

import java.util.ArrayList;
import java.util.List;

import javax.ejb.Remove;
import javax.ejb.Stateful;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

import org.jboss.seam.annotations.Create;
import org.jboss.seam.annotations.In;
import org.jboss.seam.annotations.Name;
import org.jboss.seam.annotations.Out;

import pl.edu.agh.iosr.gamblingzone.model.Participant;
import pl.edu.agh.iosr.gamblingzone.utils.DAOFactory;
import pl.edu.agh.iosr.gamblingzone.dao.ParticipantDAO;

@Stateful
@Name("participantsManage")
public class ParticipantsManageAction implements ParticipantsManage {

	/** The dao. */
	@In(required=true)
	DAOFactory dao;

	private List<Participant> all;
	private ParticipantDAO participantDAO;
	private String newParticipantName;
	private String newParticipantDesc;

	@Create
	public void init() {
		participantDAO = dao.getParticipantDAO();
		newParticipantName = "";
		newParticipantDesc = "";
	}

	@Remove
	public void remove() {
		// NOTHING LEFT TO BE DONE
	}

	public void removeParticipant(Participant p) {
		participantDAO.makeTransient(p);
	}

	public void addParticipant() {
		if ((!(newParticipantDesc.equals(""))) && (!newParticipantName.equals(""))) {
			Participant p = new Participant();
			p.setName(newParticipantName);
			p.setDescription(newParticipantDesc);
			participantDAO.makePersistent(p);
		}
		newParticipantDesc = "";
		newParticipantName = "";

	}

	public List<Participant> getAll() {
		all = participantDAO.findAll();
		return all;
	}

	public void setNewParticipantName(String newParticipantName) {
		this.newParticipantName = newParticipantName;
	}

	public void setNewParticipantDesc(String newParticipantDesc) {
		this.newParticipantDesc = newParticipantDesc;
	}

	public String getNewParticipantName() {
		return newParticipantName;
	}

	public String getNewParticipantDesc() {
		return newParticipantDesc;
	}
}
